import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
} from '@nestjs/common';
import { CartService } from './cart.service';
import { ApiProperty } from '@nestjs/swagger';

@Controller('cart_web')
export class CartController {
  constructor(private readonly cartService: CartService) {}

  // @Post()
  // create(@Body() createCartDto: CreateCartDto) {
  //   return this.cartService.create(createCartDto);
  // }

  @Post('/add_cart')
  addCart(@Req() request, @Body() params) {
    const userId = request.managerInfo.sub;

    return this.cartService.addCart(userId, params);
  }

  @Post('/cart_order')
  addOrder(@Req() request: any, @Body() params) {
    const userId = request.managerInfo.sub;
    return this.cartService.addCartOrder(userId, params);
  }

  @Get('get_cart')
  @ApiProperty({ description: '分页获取用户的购物车情况' })
  findCart(@Req() req) {
    return this.cartService.findAll(+req.managerInfo.sub);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.cartService.findOne(+id);
  }

  // @Patch(':id')
  // update(@Param('id') id: string, @Body() updateCartDto: UpdateCartDto) {
  //   return this.cartService.update(+id, updateCartDto);
  // }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.cartService.remove(+id);
  }
}
